home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 2
/
Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso
/
Aminet
/
gfx
/
misc
/
CutItOut.lha
/
cut2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-01-04
|
6KB
|
284 lines
#include <dos/dos.h>
#include <exec/memory.h>
#include <custom/iff.h>
#include <float.h>
#include <graphics/scale.h>
#include <exec/libraries.h>
#include <libraries/asl.h>
#include <clib/asl_protos.h>
#include <stdio.h>
#include "cutitoutwin.c"
struct BitMap mybitmap;
struct IFFL_BMHD *bmhd;
WORD kleur[256];
int bitgood = FALSE;
struct Library *IFFBase=NULL, *AslBase=NULL;
struct TagItem frtags[] =
{ TAG_DONE };
struct FileRequester *fr=NULL;
wbmain()
{
main();
}
main()
{
if(!openlibs()) die("Sorry, some library missing...");
if(SetupScreen()!=0) die("Sorry, couldn't open screen...");
if(OpenCutBitmapWindow()!=0) die("Sorry, couldn't open window...");
HandleCutBitmapIDCMP();
die("That's all folks!");
}
die(txt)
unsigned char *txt;
{
printf("%s\n\n",txt);
CloseCutBitmapWindow();
CloseDownScreen();
if(bitgood) MyFreeBitMap(&mybitmap);
closelibs();
exit(0);
}
viewClicked()
{ return(TRUE); }
loadClicked()
{
IFFL_HANDLE iff;
long planesize,i;
UBYTE file[256];
static struct TagItem frt1[] =
{ ASL_Hail, (ULONG)"Cut-it-out! Load IFF",TAG_DONE };
if(bitgood) MyFreeBitMap(&mybitmap);
if(AslRequest(fr,frt1)==NULL)
return(FALSE);
strcpy(file,fr->rf_Dir);
AddPart(file,fr->rf_File,255);
if(iff = IFFL_OpenIFF(file, IFFL_MODE_READ) )
{ if(bmhd = IFFL_GetBMHD(iff) )
{ IFFL_GetViewModes(iff);
IFFL_GetColorTab(iff,kleur);
InitBitMap(&mybitmap,bmhd->nPlanes,bmhd->w,bmhd->h);
planesize=mybitmap.BytesPerRow*mybitmap.Rows;
for(i=0; i<bmhd->nPlanes; ++i)
if(!(mybitmap.Planes[i]=AllocMem(planesize,MEMF_CLEAR)))
{ MyFreeBitMap(&mybitmap);
IFFL_CloseIFF(iff);
die("Sorry, no memory for picture-storage...");
}
bitgood=TRUE;
IFFL_DecodePic(iff, &mybitmap);
refreshit();
}
IFFL_CloseIFF(iff);
}
return(TRUE);
}
refreshit()
{
struct BitMap *dbm;
struct BitScaleArgs bms;
if(!bitgood) return(FALSE);
dbm=CutBitmapWnd->RPort->BitMap;
bms.bsa_SrcX=0L;
bms.bsa_SrcY=0L;
bms.bsa_SrcWidth=bmhd->w;
bms.bsa_SrcHeight=bmhd->h;
bms.bsa_XSrcFactor=bmhd->w;
bms.bsa_YSrcFactor=bmhd->h;
bms.bsa_DestX=leftbevel();
bms.bsa_DestY=topbevel();
bms.bsa_DestWidth=bevelwidth();
bms.bsa_DestHeight=bevelheight();
bms.bsa_XDestFactor=bms.bsa_DestWidth;
bms.bsa_YDestFactor=bms.bsa_DestHeight;
bms.bsa_SrcBitMap=&mybitmap;
bms.bsa_DestBitMap=dbm;
bms.bsa_Flags=0;
BitMapScale(&bms);
}
leftbevinwin()
{ return(OffX+ComputeX(10+4));
}
leftbevel()
{ return(CutBitmapWnd->LeftEdge+OffX+ComputeX(10+4));
}
topbevinwin()
{ return(OffY+ComputeY(5+2));
}
topbevel()
{ return(CutBitmapWnd->TopEdge+OffY+ComputeY(5+2));
}
rightbevinwin()
{ return(leftbevinwin()+bevelwidth());
}
rightbevel()
{ return(leftbevel()+bevelwidth());
}
bottombevinwin()
{ return(topbevinwin()+bevelheight());
}
bottombevel()
{ return(topbevel()+bevelheight());
}
bevelwidth()
{ return(ComputeX(CutBitmapWidth-20)-2*OffX-3-8);
}
bevelheight()
{ return(ComputeY(CutBitmapHeight-10)-2*OffY-4);
}
saveClicked(zoomx,zoomy)
int *zoomx,*zoomy;
{
float scalew,scaleh;
int result;
static struct EasyStruct es1 =
{ sizeof(struct EasyStruct),
0,
"Information",
"IFF file stored succesfully.\nGood luck!",
"Ok"
};
static struct EasyStruct es2 =
{ sizeof(struct EasyStruct),
0,
"Information",
"I'm sorry, something went\ncompletely wrong there...",
"Ok"
};
UBYTE file[256];
static struct TagItem frt2[] =
{ ASL_Hail,(ULONG)"Cut-it-out! Load IFF",
ASL_FuncFlags, FILF_SAVE,
TAG_DONE
};
if(AslRequest(fr,frt2)==NULL)
return(FALSE);
strcpy(file,fr->rf_Dir);
AddPart(file,fr->rf_File,255);
scalew=((float)bmhd->w)/bevelwidth();
scaleh=((float)bmhd->h)/bevelheight();
if((result=IFFL_SaveClip(file,&mybitmap,
kleur,1,
(long)((zoomx[0]-leftbevinwin())*scalew/8.0),
(long)((zoomy[0]-topbevinwin())*scaleh),
(long)((zoomx[1]-zoomx[0])*scalew/8.0),
(long)((zoomy[1]-zoomy[0])*scaleh)))==0)
{ EasyRequest(CutBitmapWnd,&es2,NULL,NULL); }
else { EasyRequest(CutBitmapWnd,&es1,NULL,NULL); }
return(TRUE);
}
expandClicked()
{ return(TRUE); }
showfullClicked()
{ return(TRUE); }
openlibs()
{
if(IFFBase = OpenLibrary(IFFNAME, IFFVERSION) )
if(AslBase = OpenLibrary("asl.library",37L))
if(fr=(struct FileRequester *)AllocAslRequest(ASL_FileRequest,frtags))
return(TRUE);
return(FALSE);
}
closelibs()
{
if(fr) FreeAslRequest(fr);
if(IFFBase) CloseLibrary(IFFBase);
if(AslBase) CloseLibrary(AslBase);
}
MyFreeBitMap(bm)
struct BitMap *bm;
{
LONG planesize=bm->BytesPerRow*bm->Rows,i;
for(i=0; i<bm->Depth; ++i)
if(bm->Planes[i])
{ FreeMem(bm->Planes[i],planesize);
bm->Planes[i]=0;
}
bitgood=FALSE;
}
drawcross(eraseold,drawnew,x,y)
BOOL eraseold,drawnew;
int x,y;
{
static oldx,oldy;
if(eraseold)
{ Move(CutBitmapWnd->RPort,leftbevinwin(),oldy);
Draw(CutBitmapWnd->RPort,rightbevinwin(),oldy);
Move(CutBitmapWnd->RPort,oldx,topbevinwin());
Draw(CutBitmapWnd->RPort,oldx,bottombevinwin());
}
if(drawnew)
{ Move(CutBitmapWnd->RPort,leftbevinwin(),y);
Draw(CutBitmapWnd->RPort,rightbevinwin(),y);
Move(CutBitmapWnd->RPort,x,topbevinwin());
Draw(CutBitmapWnd->RPort,x,bottombevinwin());
}
oldx=x;
oldy=y;
}
drawrubber(eraseold,drawnew,x,y,zoomx,zoomy)
BOOL eraseold,drawnew;
int x,y,*zoomx,*zoomy;
{
static oldx,oldy;
if(eraseold)
{ Move(CutBitmapWnd->RPort,zoomx[0],zoomy[0]);
Draw(CutBitmapWnd->RPort,zoomx[0],oldy);
Draw(CutBitmapWnd->RPort,oldx,oldy);
Draw(CutBitmapWnd->RPort,oldx,zoomy[0]);
Draw(CutBitmapWnd->RPort,zoomx[0],zoomy[0]);
}
if(drawnew)
{ Move(CutBitmapWnd->RPort,zoomx[0],zoomy[0]);
Draw(CutBitmapWnd->RPort,zoomx[0],y);
Draw(CutBitmapWnd->RPort,x,y);
Draw(CutBitmapWnd->RPort,x,zoomy[0]);
Draw(CutBitmapWnd->RPort,zoomx[0],zoomy[0]);
}
oldx=x;
oldy=y;
}